
package com.zcp.notepad;

import com.zcp.notepad.NotePad.Notes;
import com.zcp.notepad.NotePad.Settings;
import com.zcp.notepad.NotePad.WidgetInfo;

import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.database.DataSetObserver;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
import android.widget.Toast;

import java.util.LinkedList;

public class NoteListActivity extends ListActivity {

    private static final String TAG = "NoteListActivity";

    private static final String[] PROJECTION = new String[] {
            Notes._ID, // 0
            Notes.TITLE, // 1
            Notes.MODIFIED_DATE,// 2
            Notes.COLOR,// 3
            Notes.LOCK,// 4
            Notes.REMIND,// 5
            Notes.REMIND_TIME,// 6
    };

    private static final String[] PASSWORD = new String[] {
            Settings._ID, // 0
            Settings.PASSWORD
    // 1
    };

    private static final int COLUMN_INDEX_ID = 0;

    private static final int COLUMN_INDEX_TITLE = 1;

    private static final int COLUMN_INDEX_MODIFIED_DATE = 2;

    private static final int COLUMN_INDEX_COLOR = 3;

    private static final int COLUMN_INDEX_LOCK = 4;

    private static final int COLUMN_INDEX_REMAIN = 5;

    private static final int COLUMN_INDEX_REMAIN_TIME = 6;

    private boolean isWidgetRequest;

    private int mWidgetId;

    private int mWidgetSize;

    private ImageView footerView;

    private MenuItem deleteMenu;// 弹出删除菜单

    private MenuItem exportMenu;// 弹出导出菜单

    private TextView noteNumberText;// 标题栏

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Intent intent = getIntent();
        if (intent.getData() == null) {
            intent.setData(Notes.CONTENT_URI);
        }

        noteNumberText = (TextView) this.findViewById(R.id.noteNumber);
        mWidgetId = intent.getIntExtra("widget_id", -1);
        mWidgetSize = intent.getIntExtra("widget_size", -1);
        isWidgetRequest = mWidgetId != -1 ? true : false;
        initializeData();
        if (isWidgetRequest) {
            noteNumberText.setText(R.string.chooseNote);
        }
        Cursor cursor = managedQuery(getIntent().getData(), PROJECTION, null, null,
                Notes.DEFAULT_SORT_ORDER);

        // Used to map notes entries from the database to views
        SimpleCursorAdapter adapter = new MyAdapter(this, R.layout.noteslist_item, cursor,
                new String[] {}, new int[] {});
        footerView = new ImageView(this);
        footerView.setImageResource(R.drawable.shadow);
        footerView.setBackgroundColor(Color.TRANSPARENT);
        footerView.setClickable(false);

        if (adapter.getCount() <= 0) {
            footerView.setVisibility(View.GONE);
        } else {
            footerView.setVisibility(View.VISIBLE);
        }

        getListView().addFooterView(footerView, null, false);

        adapter.registerDataSetObserver(new DataSetObserver() {

            @Override
            public void onChanged() {
                updateNoteNumberText();
                if (getListAdapter().getCount() <= 0) {
                    footerView.setVisibility(View.GONE);
                } else {
                    footerView.setVisibility(View.VISIBLE);
                }

                super.onChanged();
            }

        });
        // 添加底部阴影栏
        setListAdapter(adapter);
        registerForContextMenu(getListView());
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);
        menu.add(0, 1, 1, R.string.newNote).setIcon(R.drawable.new_note);
        deleteMenu = menu.add(0, 2, 2, R.string.Delete).setIcon(R.drawable.delete);
        menu.add(0, 3, 3, R.string.Password_setting).setIcon(R.drawable.lock);
        exportMenu = menu.add(0, 4, 4, R.string.Export_txt_file).setIcon(R.drawable.export_txt);
        setMunuEnable();
        return true;
    }

    @Override
    protected void onResume() {
        updateNoteNumberText();
        super.onResume();
    }

    /**
     * 根据list中item数量来控制菜单的显示。
     */
    private void setMunuEnable() {
        if (deleteMenu != null && exportMenu != null) {
            deleteMenu.setEnabled(true);
            exportMenu.setEnabled(true);
            if (this.getListView().getAdapter().getCount() <= 0) {
                deleteMenu.setEnabled(false);
                exportMenu.setEnabled(false);
            }
        }
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_MENU) {
            setMunuEnable();

        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case 1:
                openNewNoteActivity();
                return true;
            case 2: {
                Intent intent = new Intent(this, NoteDeleteActivity.class);
                startActivity(intent);
                return true;
            }
            case 3: {
                Intent intent = new Intent(this, PasswordSettingActivity.class);
                startActivity(intent);
                return true;
            }
            case 4: {
                Intent intent = new Intent(this, ExportActivity.class);
                startActivity(intent);
                return true;
            }

        }
        return false;
    }

    @Override
    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
        AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;

        View item = info.targetView;
        ImageView lockView = null;
        ImageView remindView = null;

        if (item != null) {
            TextView titleView = (TextView) item.findViewById(R.id.noteTitle);
            menu.setHeaderTitle(titleView.getText());
            lockView = (ImageView) item.findViewById(R.id.lock);
            remindView=(ImageView) item.findViewById(R.id.remain);
        }

        menu.add(0, 1, 0, R.string.Share);
        menu.add(0, 2, 1, R.string.Add_to_homeswcreen);
        menu.add(0, 3, 2, R.string.Delete);

        if (lockView != null && (lockView.getVisibility() == View.VISIBLE)) {
            menu.add(0, 4, 3, R.string.unlock);
        } else {
            menu.add(0, 4, 3, R.string.lock);
        }
        if (remindView != null && (remindView.getVisibility() == View.VISIBLE)) {
            menu.add(0, 5, 4, R.string.unremind);
        } else {
            menu.add(0, 5, 4, R.string.remind);
        }
        
        super.onCreateContextMenu(menu, v, menuInfo);
    }

    @Override
    public boolean onContextItemSelected(MenuItem item) {

        AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo) item.getMenuInfo();
        View view = menuInfo.targetView;
        TextView timeView = (TextView) view.findViewById(R.id.noteTime);
        TextView titleView = (TextView) view.findViewById(R.id.noteTitle);
        int[] itemTag = (int[]) timeView.getTag();
        final int noteId = itemTag[0];
        final int isLock = itemTag[1];
        final int isRemindVisible=itemTag[2];
        switch (item.getItemId()) {
            case 1: {
                if (isLock == NotePad.DataValue.IS_LOCK) {
                    Util.getCheckPasswordDialog(this, getString(R.string.Share), null,
                            shareOnClickOkCancelClick, new String[] {
                                    String.valueOf(noteId), titleView.getText().toString()
                            }).show();
                } else {
                    Util.shareNote(this, noteId, titleView.getText().toString());
                }
                break;
            }
            case 2: {

                if (isLock == NotePad.DataValue.IS_LOCK) {
                    Util.getCheckPasswordDialog(this, getString(R.string.Add_to_homeswcreen), null,
                            addHomeOnClickOkCancelClick, new String[] {
                                    String.valueOf(noteId), titleView.getText().toString()
                            }).show();
                } else {
                    Util.addShortcutToOptions(this, titleView.getText().toString(), noteId);
                }
                break;
            }
            case 3: {
                if (isLock == NotePad.DataValue.IS_LOCK) {
                    Util.getCheckPasswordDialog(this, getString(R.string.Delete), null,
                            deleteOnClickOkCancelClick, String.valueOf(noteId)).show();

                } else {
                    final LinkedList<String> ids = new LinkedList<String>();
                    ids.add(String.valueOf(noteId));
                    final Context context = this;
                    DialogInterface.OnClickListener okInface = new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                            Util.deleteNoteById(context, ids);
                            ((SimpleCursorAdapter) getListAdapter()).notifyDataSetChanged();
                        }
                    };
                    String title = getString(R.string.Delete);
                    String message = getString(R.string.delete_one_note_message, 1);
                    Util.getOkCancelDialog(this, title, message, null, okInface).show();
                }
                break;
            }
            case 4: {
                if (isLock == NotePad.DataValue.IS_LOCK) {// 解锁
                    Util.getUnlockDialog(this, noteId, lockAndUnlockListener).show();
                } else {// 加锁

                    if (Util.isSettingPasswrd(this)) {
                        ContentValues values = new ContentValues();
                        values.put(NotePad.Notes.LOCK, NotePad.DataValue.IS_LOCK);
                        getContentResolver().update(NotePad.Notes.CONTENT_URI, values,
                                NotePad.Notes._ID + " = " + noteId, null);
                    } else {
                        // 未设置密码时加锁
                        new AlertDialog.Builder(this)
                                .setTitle(getString(R.string.set_note_password))
                                .setMessage(getString(R.string.ask_set_note_password))
                                .setIcon(android.R.drawable.ic_dialog_info)
                                .setPositiveButton(getString(R.string.input_ok),
                                        new DialogInterface.OnClickListener() {
                                            @Override
                                            public void onClick(DialogInterface dialog, int which) {
                                                Util.getSettingPasswordDialog(
                                                        NoteListActivity.this,
                                                        getString(R.string.set_note_password),
                                                        settingPasswordListener, new String[] {
                                                                "lockUnLock", noteId + ""
                                                        }).show();
                                            }
                                        })
                                .setNegativeButton(getString(R.string.input_cancel), null).show();
                    }
                }
                ((SimpleCursorAdapter) getListAdapter()).notifyDataSetChanged();
                break;
            }
            case 5: {
                if (isRemindVisible == View.VISIBLE) {// 取消提醒

                    Util.cancelAlarmSet(this, noteId + "");
                } else {
                    // 设置提醒
                    Util.setNotice(this, noteId + "", null);
                }
                break;
            }
            
        }
        return super.onContextItemSelected(item);
    }

    @Override
    protected void onStart() {
        boolean isExit = getIntent().getBooleanExtra("isExit", false);
        if (isExit) {
            finish();
        }
        super.onStart();
    }

    private void updateNoteNumberText() {
        // 若来自widget的请求，标题栏固定为choose note
        if (isWidgetRequest) {
            return;
        }
        int number = getListAdapter().getCount();
        noteNumberText.setText(getString(R.string.noteNumber, number));
    }

    /**
     * 初始化数据.
     */
    private void initializeData() {
        addNote = (Button) findViewById(R.id.addNoteBut);
        initializeListener();
    }

    private void initializeListener() {
        addNote.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                openNewNoteActivity();
            }
        });
    }

    private void openNewNoteActivity() {
        Intent intent = new Intent(this, NoteEditorActivity.class);
        intent.setData(Notes.CONTENT_URI);
        if (isWidgetRequest) {
            intent.putExtra("widget_id", mWidgetId);
            intent.putExtra("widget_size", mWidgetSize);
        }
        intent.setAction(Intent.ACTION_INSERT);

        this.startActivity(intent);
    }

    /**
     * 自定义适配器
     * 
     * @author Administrator
     */
    class MyAdapter extends SimpleCursorAdapter {

        public MyAdapter(Context context, int layout, Cursor c, String[] from, int[] to) {
            super(context, layout, c, from, to);

        }

        TextView titleView;

        TextView timeView;

        ImageView lockView;

        ImageView remainView;

        @Override
        public void bindView(View view, Context context, Cursor cursor) {

            titleView = (TextView) view.findViewById(R.id.noteTitle);
            timeView = (TextView) view.findViewById(R.id.noteTime);
            lockView = (ImageView) view.findViewById(R.id.lock);
            remainView = (ImageView) view.findViewById(R.id.remain);
            String title;
            if (cursor != null) {
                title = cursor.getString(COLUMN_INDEX_TITLE);
                long modifiedDate = cursor.getLong(COLUMN_INDEX_MODIFIED_DATE);
                int note_id = cursor.getInt(COLUMN_INDEX_ID);
                String color = cursor.getString(COLUMN_INDEX_COLOR);
                String dateStr = Util.getDateStr(context, modifiedDate);
                timeView.setText(dateStr);

                int lock = cursor.getInt(COLUMN_INDEX_LOCK);

                if (lock == 0) {
                    lockView.setVisibility(View.INVISIBLE);
                    titleView.setText(title);

                } else if (lock == 1) {
                    if (title.length() > 6) {
                        title = title.substring(0, 6) + "***";
                        titleView.setText(title);
                    } else {
                        titleView.setText(title);
                    }
                    lockView.setVisibility(View.VISIBLE);
                }
                // 设置是否已经提醒图片
                int remain = cursor.getInt(COLUMN_INDEX_REMAIN);
                String remindTime = cursor.getString(COLUMN_INDEX_REMAIN_TIME);
                long remindTimeLong = Long.valueOf(remindTime);
                int remindVisible=View.INVISIBLE;
                remainView.setVisibility(View.INVISIBLE);
                if (remain == NotePad.DataValue.IS_REMIND) {
                    // 过期的就不再显示
                    if (System.currentTimeMillis() < remindTimeLong) {
                        remainView.setVisibility(View.VISIBLE);
                        remindVisible=View.VISIBLE;
                    }
                }
                timeView.setTag(new int[] {
                        note_id, lock,remindVisible
                });
                Util.setRowColor(color, view);
            }
            super.bindView(view, context, cursor);
        }

    }

    private Cursor mCursor;

    private Button addNote = null;

    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {

        TextView timeView = (TextView) v.findViewById(R.id.noteTime);
        TextView titleView = (TextView) v.findViewById(R.id.noteTitle);
        int[] itemTag = (int[]) timeView.getTag();
        final int note_id = itemTag[0];
        final int lock = itemTag[1];

        Uri uri = ContentUris.withAppendedId(getIntent().getData(), note_id);
        if (isWidgetRequest) {
            ContentValues values = new ContentValues();
            values.put(WidgetInfo.WIDGET_ID, mWidgetId);
            values.put(WidgetInfo.NOTE_ID, note_id);
            values.put(WidgetInfo.WIDGET_SIZE, mWidgetSize);
            this.getContentResolver().insert(WidgetInfo.CONTENT_URI, values);
            Intent widgetIntent = new Intent();
            widgetIntent.putExtra("note_id", note_id);
            widgetIntent.putExtra("widget_id", mWidgetId);
            widgetIntent.putExtra("widget_size", mWidgetSize);
            widgetIntent.setAction(NoteWidgetProvider.ACTION_UPDATE_BY_WIDGETID);
            this.sendBroadcast(widgetIntent);
            finish();
            return;
        }

        final Intent intent = new Intent(this, NoteEditorActivity.class);
        intent.setData(uri);
        intent.putExtra("isListRequest", true);
        intent.setAction(Intent.ACTION_EDIT);

        // 是否加锁，加锁则输入密码
        if (lock == NotePad.DataValue.IS_LOCK) {
            LayoutInflater inflater = getLayoutInflater();
            View layout = inflater.inflate(R.layout.password_setting_dialog,
                    (ViewGroup) findViewById(R.id.dialog_passwod_setting));

            final TextView passwordTv = (TextView) layout.findViewById(R.id.password_text);
            final TextView descTv = (TextView) layout.findViewById(R.id.password_tv);

            new AlertDialog.Builder(this)
                    .setTitle(getString(R.string.input_password))
                    .setIcon(android.R.drawable.ic_dialog_info)
                    .setView(layout)
                    .setPositiveButton(getString(R.string.input_ok),
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    String password = passwordTv.getText().toString();

                                    if ("".equals(password)) {
                                        descTv.setText(R.string.wrong_change_password);
                                        Util.setDialogCanDismiss(dialog, false);
                                        dialog.dismiss();
                                    } else {
                                        mCursor = getContentResolver().query(
                                                NotePad.Settings.CONTENT_URI, PASSWORD, null, null,
                                                null);
                                        if (mCursor.moveToFirst()) {
                                            String queryPassword = mCursor.getString(1).toString();
                                            if (password.equals(queryPassword)) {
                                                Util.setDialogCanDismiss(dialog, true);
                                                dialog.dismiss();
                                                startActivity(intent);
                                            } else {
                                                descTv.setText(R.string.wrong_change_password);
                                                passwordTv.setText("");
                                                Util.setDialogCanDismiss(dialog, false);
                                                dialog.dismiss();
                                            }
                                        } else {// 未设置密码
                                            Toast.makeText(NoteListActivity.this,
                                                    "Please Set PassWord", Toast.LENGTH_SHORT)
                                                    .show();
                                        }
                                    }
                                }
                            })
                    .setNegativeButton(getString(R.string.input_cancel),
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {

                                    Util.setDialogCanDismiss(dialog, true);
                                    dialog.dismiss();
                                }
                            }).show();
        } else {
            startActivity(intent);
        }

    }

    private void showText(int StringId) {
        Toast.makeText(this, getString(StringId), Toast.LENGTH_SHORT).show();
    }

    private SettingPasswordInterfaceOkCancelClick settingPasswordListener = new SettingPasswordInterfaceOkCancelClick();

    private LockAndUnlockInterfaceOkCancelClick lockAndUnlockListener = new LockAndUnlockInterfaceOkCancelClick();

    private class SettingPasswordInterfaceOkCancelClick implements InterfaceOkCancelClick {
        @Override
        public void dealWithOk(boolean isCheckOk, boolean valid, DialogInterface dialog,
                TextView passwordTv, Object tagObject) {

            String[] tagObj = (String[]) tagObject;
            if (tagObject != null) {
                // 设置密码操作
                String tag = passwordTv.getTag().toString();
                String passwordText = passwordTv.getText().toString();

                if ("".equals(passwordText)) {
                    Util.setDialogCanDismiss(dialog, false);
                    dialog.dismiss();
                    showText(R.string.wrong_change_password);
                    return;
                }

                if (isCheckOk) {
                    Util.setDialogCanDismiss(dialog, true);
                    dialog.dismiss();
                    if (tag.equals("insert")) {
                        ContentValues values = new ContentValues();
                        values.put(Settings.PASSWORD, passwordText);
                        getContentResolver().insert(NotePad.Settings.CONTENT_URI, values);
                        Toast.makeText(NoteListActivity.this,
                                getString(R.string.new_password_save), Toast.LENGTH_SHORT).show();

                    } else if (tag.equals("update")) {
                        ContentValues values = new ContentValues();
                        values.put(Settings.PASSWORD, passwordText);
                        getContentResolver().update(NotePad.Settings.CONTENT_URI, values, null,
                                null);
                        Toast.makeText(NoteListActivity.this,
                                getString(R.string.new_password_save), Toast.LENGTH_SHORT).show();
                    }

                    // 设置密码并加锁
                    if ("lockUnLock".equals(tagObj[0])) {
                        ContentValues values = new ContentValues();
                        int noteId = Integer.parseInt(tagObj[1]);
                        values.put(NotePad.Notes.LOCK, NotePad.DataValue.IS_LOCK);
                        getContentResolver().update(NotePad.Notes.CONTENT_URI, values,
                                NotePad.Notes._ID + " = " + noteId, null);

                    }
                } else {
                    Util.setDialogCanDismiss(dialog, false);
                    dialog.dismiss();
                    showText(R.string.wrong_change_password);
                }

                return;
            }
        }

        @Override
        public void dealWithCancel(DialogInterface dialog, Object tagObject) {
            Util.setDialogCanDismiss(dialog, true);
            dialog.dismiss();
        }

    }

    private class LockAndUnlockInterfaceOkCancelClick implements InterfaceOkCancelClick {
        @Override
        public void dealWithOk(boolean isCheckOk, boolean valid, DialogInterface dialog,
                TextView passwordTv, Object tagObject) {

            if (isCheckOk) {
                int noteId = Integer.parseInt(passwordTv.getTag().toString());
                Util.setDialogCanDismiss(dialog, true);
                dialog.dismiss();
                ContentValues values = new ContentValues();
                values.put(NotePad.Notes.LOCK, NotePad.DataValue.IS_UNLOCK);
                getContentResolver().update(NotePad.Notes.CONTENT_URI, values,
                        NotePad.Notes._ID + " = " + noteId, null);
            } else {
                Util.setDialogCanDismiss(dialog, false);
                dialog.dismiss();
            }
        }

        @Override
        public void dealWithCancel(DialogInterface dialog, Object tagObject) {
            Util.setDialogCanDismiss(dialog, true);
            dialog.dismiss();
        }

    }

    private ShareOnClickOkCancelClick shareOnClickOkCancelClick = new ShareOnClickOkCancelClick();

    private class ShareOnClickOkCancelClick implements InterfaceOkCancelClick {
        @Override
        public void dealWithOk(boolean isCheckOk, boolean valid, DialogInterface dialog,
                TextView passwordTv, Object tagObject) {

            if (isCheckOk) {
                Util.setDialogCanDismiss(dialog, true);
                dialog.dismiss();
                if (tagObject != null) {
                    String[] tag = (String[]) tagObject;
                    shareNote(Integer.valueOf(tag[0]).intValue(), tag[1]);
                }

            } else {
                Util.setDialogCanDismiss(dialog, false);
                dialog.dismiss();
            }
        }

        @Override
        public void dealWithCancel(DialogInterface dialog, Object tagObject) {
            Util.setDialogCanDismiss(dialog, true);
            dialog.dismiss();
        }

    }

    private AddHomeOnClickOkCancelClick addHomeOnClickOkCancelClick = new AddHomeOnClickOkCancelClick();

    private class AddHomeOnClickOkCancelClick implements InterfaceOkCancelClick {
        @Override
        public void dealWithOk(boolean isCheckOk, boolean valid, DialogInterface dialog,
                TextView passwordTv, Object tagObject) {

            if (isCheckOk) {
                Util.setDialogCanDismiss(dialog, true);
                dialog.dismiss();
                if (tagObject != null) {
                    String[] tag = (String[]) tagObject;
                    addShortcutToOptions(Integer.valueOf(tag[0]).intValue(), tag[1]);
                }

            } else {
                Util.setDialogCanDismiss(dialog, false);
                dialog.dismiss();
            }
        }

        @Override
        public void dealWithCancel(DialogInterface dialog, Object tagObject) {
            Util.setDialogCanDismiss(dialog, true);
            dialog.dismiss();
        }

    }

    private DeleteOnClickOkCancelClick deleteOnClickOkCancelClick = new DeleteOnClickOkCancelClick();

    private class DeleteOnClickOkCancelClick implements InterfaceOkCancelClick {
        @Override
        public void dealWithOk(boolean isCheckOk, boolean valid, DialogInterface dialog,
                TextView passwordTv, Object tagObject) {

            if (isCheckOk) {
                Util.setDialogCanDismiss(dialog, true);
                dialog.dismiss();
                if (tagObject != null) {
                    String tag = (String) tagObject;
                    final LinkedList<String> ids = new LinkedList<String>();
                    ids.add(tag);
                    DialogInterface.OnClickListener okInface = new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                            deleteNoteById(ids);
                        }
                    };
                    String title = getString(R.string.Delete);
                    String message = getString(R.string.delete_this_message, 1);
                    Util.getOkCancelDialog(passwordTv.getContext(), title, message, null, okInface)
                            .show();

                }

            } else {
                Util.setDialogCanDismiss(dialog, false);
                dialog.dismiss();
            }
        }

        @Override
        public void dealWithCancel(DialogInterface dialog, Object tagObject) {
            Util.setDialogCanDismiss(dialog, true);
            dialog.dismiss();
        }

    }

    private void deleteNoteById(LinkedList<String> ids) {
        Util.deleteNoteById(this, ids);
    }

    private void shareNote(int note_id, String title) {
        Util.shareNote(this, note_id, title);
    }

    private void addShortcutToOptions(int note_id, String title) {
        Util.addShortcutToOptions(this, title, note_id);
    }

}
